/*
 * @(#)XfvhdlCreateFile.java        3.0                       2004/09/14
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.xfvhdl;

import java.io.*;

/**
* Clase que genera un fichero a partir de una cadena.
* @author Jos� Mar�a �vila Maireles, <b>e-mail</b>: josavimai@alum.us.es
* @version 3.0
*/
public class XfvhdlCreateFile{
	

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//			  CONSTRUCTOR DE LA CLASE					 	   
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//	
	/**
	* M�todo construtor de la clase.
	*/
	public XfvhdlCreateFile (String fileName, String code) {
		createFile(fileName,code);
	}
	

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//			  M�TO_DOS P�BLICOS DE LA CLASE				       
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
	/**
	* M�todo que crea el fichero de nombre file y con el contenido de 
	* code.
	* @param file Nombre del fichero que se creara.
	* @param code Contenido del fichero file.
	*/
	private void createFile(String fileName, String code) {
		byte buf[] = code.getBytes();

		// Creo el directorio de salida si no existe.
		File temp = new File(XfvhdlProperties.outputDirectory);
		if (!temp.exists()){
			if(!temp.mkdirs()){
				new XfvhdlError(2);
			}
		}
		// Guardo informaci�n del directorio de salida.
		if(XfvhdlProperties.fileDir == null)
				XfvhdlProperties.fileDir=temp.getAbsolutePath();

		File file = new File(XfvhdlProperties.outputDirectory,fileName);	
		try {
			OutputStream stream = new FileOutputStream(file);
			stream.write(buf);
			stream.close();
		}
		catch (IOException e) {}
	}
	
} // Fin de la clase
